// 引入vue的方式1-通过es6import语法
// 去node_modules/vue
// 取消从node_modules拿
// 方式1-手动修改const Vue = window.Vue
// 方式2-让webpack给我们改
import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
// 方式1-单个注册指令
/*
import { imgerror } from '@/directives/index.js'
Vue.directive('imgerror', imgerror)
*/
// 方式2.1-批量注册指令,通过for in
// 参考:https://es6.ruanyifeng.com/#docs/module#%E6%A8%A1%E5%9D%97%E7%9A%84%E6%95%B4%E4%BD%93%E5%8A%A0%E8%BD%BD
// directives = {imgerror: imgerror}
/*
import * as directives from '@/directives/index.js'
for (const key in directives) {
  Vue.directive(key, directives[key])
}
*/
// 方式2 通过批量注册指令，通过Object.keys
import * as directives from '@/directives/index.js'
Object.keys(directives).forEach(key => {
  // console.log('key', key)
  Vue.directive(key, directives[key])
})
import * as filters from '@/filters/index.js'
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
import checkPermission from '@/mixin/checkPermission.js'
Vue.mixin(checkPermission)
/*
Vue.prototype.checkPermission = function(key) {
  try {
    // 通过this指向
    // return this.$store.state.user.userInfo.roles.points.includes(key)
    // 使用store
    return store.state.user.userInfo.roles.points.includes(key)
  } catch (e) {
    return false
  }
}/*
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
import Components from '@/components/index.js'
Vue.use(Components)
import i18n from './lang'
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
